<extend name="Public/base" />

<block name="body">
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>爬虫新闻</h2>
    </div>
    <p>* 除了图片和文字, 其他内容发布到咨询时候会被屏蔽掉</p>
    <p>* 发布到资讯时候请选择游戏</p>
    <div class="cf">
        <div class="fl">
            <div class="btn-group">
              <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                {$game|default=所有游戏} <span class="caret"></span>
              </button>
              <ul class="dropdown-menu" role="menu">
                <li><a href="{:U('index')}">全部</a></li>
                <volist name="allGames" id="g">
                    <li><a href="{:U('index?'.$args, ['game' => $g])}">{$g}</a></li>
                </volist>
              </ul>
            </div>
        </div>

        <!-- 高级搜索 -->
        <div class="search-form fr cf">
            <div class="sleft">
                <input type="text" name="title" class="search-input" value="{:I('title')}" placeholder="请输入关键字">
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('index')}"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
    <table class="table table-bordered">
    <thead>
        <tr>
            <th>标题</th>
            <th>发布日期</th>
            <th>游戏</th>
            <th>来源</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
        <notempty name="_list">
        <volist name="_list" id="vo">
        <tr>
            <td>{$vo.title}</td>
            <td><span>{$vo.date}</span></td>
            <td>
                {$vo.game}
            </td>
            <td>
                {$vo.web_name} @ {$vo.author}
            </td>
            <td><eq name="vo.submited" value="1"><span class="label label-success">已发布</span></eq></td>
            <td>
                <button data-toggle="modal" data-target="#previewBox" data-preview='{$key}' class="btn btn-default btn-xs preview"><i class="glyphicon glyphicon-eye-open"></i>预览</button>
                <a class="btn btn-default btn-xs" title="添加到资讯" href="{:U('news/add?from_crawle='.$key)}"><i class="glyphicon glyphicon-pencil"></i>发布到资讯</a>
            </td>
        </tr>
        </volist>
        <else/>
        <td colspan="8" class="text-center"> aOh! 暂时还没有内容! </td>
        </notempty>
    </tbody>
    </table>
    </div>
    <div class="page">
        {$_page}
    </div>


    <div class="modal fade" id="previewBox" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel"><i class="glyphicon glyphicon-refresh">loading...</i></h4>
          </div>
          <div class="modal-body">
          <i class="glyphicon glyphicon-refresh">loading...</i>
          </div>
        </div>
      </div>
    </div>

    <script type="text/javascript">
    $('.preview').click(function(){
        var id = $(this).data('preview');
        $.post("{:U('ajaxGetNews')}", {id: id}, function(data){
            $('.modal-title').html(data.info.title);
            $('.modal-body').html(data.info.content);
        });
    });
    </script>

</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">
    //搜索功能
    $("#search").click(function(){
        var url = $(this).attr('url');
        var query  = $('.search-form').find('input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
        window.location.href = url;
    });
    //回车搜索
    $(".search-input").keyup(function(e){
        if(e.keyCode === 13){
            $("#search").click();
            return false;
        }
    });
    //导航高亮
    highlight_subnav('{:U('index')}');
    </script>
</block>
